<?php
namespace Backend\Controllers;
use \UpYun;
class ResourceController extends BaseController
{



    public function indexAction()
    {

    }

    public function  uploadaaaAction()
    {
        $this->view->disable();
        if ($this->request->hasFiles() == true) {

            foreach ($this->request->getUploadedFiles() as $file) {
//                print_r($file);
//                $fh = fopen($file, 'rb');
//                print_r($fh);
                $path = 'uploads/' . uniqid('backend_') . '.' . $file->getExtension();
                $file->moveTo($path);
                echo json_encode(array(
                    'status' => 1,
                    'data' => '/' . $path
                ));
                break;
            }
        }

    }
    public function  uploadAction()
    {
        $this->view->disable();

        require_once($this->config->application->libDir . "/upyun/upyun.class.php");
//        echo 1;
        $upyun = new UpYun('i-yizhan-pic', 'yingzhenzhen', 'yingzhenzhen');

        if ($this->request->hasFiles() == true) {

            foreach ($this->request->getUploadedFiles() as $file) {
                $path = '/uploads/' . uniqid('backend_') . '.' . $file->getExtension();
                try {
                    $fh = fopen($file, 'rb');
                    $rsp = $upyun->writeFile($path, $fh, True);   // 上传图片，自动创建目录
                    fclose($fh);
                    echo json_encode(array(
                        'status' => 1,
                        'data' => 'http://pic.i-yizhan.com' . $path
                    ));
                    break;
                }
                catch(Exception $e) {
                    echo $e->getCode();
                    echo $e->getMessage();
                }

            }
        }
    }
}
